import random

from wish.pool.bh3_equip_pool import BH3EquipPool


def once_need_times():
    times = 0
    weapon = 0
    stigma_a = 0
    stigma_b = 0
    stigma_c = 0

    ng_up = 0

    pool = BH3EquipPool()
    while True:
        times += 1
        ng_up += 1
        if times >= 300:
            return times

        equip = pool.next()

        if equip == BH3EquipPool.UP_WEAPON:
            weapon += 1
            ng_up = 0
        if equip == BH3EquipPool.STIGMA_A:
            stigma_a += 1
            ng_up = 0
        if equip == BH3EquipPool.STIGMA_B:
            stigma_b += 1
            ng_up = 0
        if equip == BH3EquipPool.STIGMA_C:
            stigma_c += 1
            ng_up = 0

        if weapon >= 1 and stigma_a >= 1 and stigma_b >= 1 and stigma_c >= 1:
            return times

        # if ng_up == 30:
        #     ng_up = 0
        #     while True:
        #         t = random.randint(1, 4)
        #         if t == 1 and weapon == 0:
        #             weapon += 1
        #             break
        #         if t == 2 and stigma_a == 0:
        #             stigma_a += 1
        #             break
        #         if t == 3 and stigma_b == 0:
        #             stigma_b += 1
        #             break
        #         if t == 4 and stigma_c == 0:
        #             stigma_c += 1
        #             break

        if weapon >= 1 and stigma_a >= 1 and stigma_b >= 1 and stigma_c >= 1:
            return times

        if weapon >= 1 and can_wish(stigma_a, stigma_b, stigma_c):
            return times


def can_wish(a, b, c):
    if a == 0 and b == 0 or a == 0 and c == 0 or b == 0 and c == 0:
        return False

    return (a + b + c) >= 4
